//
//  QuestionsViewController.m
//  ZYZB
//
//  Created by ENERGY on 2018/7/10.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "QuestionsViewController.h"

@interface QuestionsViewController ()
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIView * topBarView;
@property (nonatomic, strong)UIButton * registerBtn;//注册认证
@property (nonatomic, strong)UIButton * objectBtn;//投标认证
@property (nonatomic, strong)UIButton * bidBtn;//标的投标
@property (nonatomic, strong)UIView * moveLineView;//移动横线
@end

@implementation QuestionsViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"常见问题";
    //返回按钮
    UIButton * backBtn = [[UIButton alloc] initWithFrame:CGRectMake(18/WIDTH_6_SCALE, 14/WIDTH_6_SCALE + 24 + 20, 24/WIDTH_6_SCALE, 30/WIDTH_6_SCALE)];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"out"] forState:UIControlStateNormal];
    UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self topBarViewSetUp];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    [self.view addSubview:self.tableView];
}
#pragma mark - init
//构造Bar
- (void)topBarViewSetUp{
    self.topBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44/WIDTH_6_SCALE)];
    [self.view addSubview:self.topBarView];
    //按钮
    int tradeBtnW = SCREEN_WIDTH/3;
    int tradeBtnH = _topBarView.height - 2/WIDTH_6_SCALE;
    for (int i = 0; i<3; i++) {
        UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(tradeBtnW*i, 0, tradeBtnW, tradeBtnH)];
        btn.tag = 5000+i;
        btn.titleLabel.font = DEF_FontSize_12;
        [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
        [btn setTitleColor:getColor(@"767676") forState:UIControlStateNormal];
        [self.topBarView addSubview:btn];
    }
    //注册认证按钮
    self.registerBtn = (UIButton *)[self.view viewWithTag:5000];
    [self.registerBtn setTitle:@"注册认证" forState:UIControlStateNormal];
    [self.registerBtn addTarget:self action:@selector(registerBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    self.registerBtn.selected = YES;
    //投标认证按钮
    self.objectBtn = (UIButton*)[self.view viewWithTag:5001];
    [self.objectBtn setTitle:@"投标认证" forState:UIControlStateNormal];
    [self.objectBtn addTarget:self action:@selector(objectBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //标的投标按钮
    self.bidBtn = (UIButton*)[self.view viewWithTag:5002];
    [self.bidBtn setTitle:@"标的投标" forState:UIControlStateNormal];
    [self.bidBtn addTarget:self action:@selector(bidBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //移动横线
    self.moveLineView = [[UIView alloc] initWithFrame:CGRectMake(0, self.registerBtn.bottom, 44/WIDTH_6_SCALE, 2/WIDTH_6_SCALE)];
    self.moveLineView.centerX = self.registerBtn.centerX;
    self.moveLineView.backgroundColor = [UIColor orangeColor];
    [_topBarView addSubview:self.moveLineView];
}
#pragma mark - action
- (void)backBtnClick:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)registerBtnClick:(UIButton *)sender{
    self.registerBtn.selected = YES;
    self.objectBtn.selected = NO;
    self.bidBtn.selected = NO;
    [UIView animateWithDuration:0.5 animations:^{
        self.moveLineView.centerX = sender.centerX;
    }];
}
- (void)objectBtnClick:(UIButton *)sender{
    self.registerBtn.selected = NO;
    self.objectBtn.selected = YES;
    self.bidBtn.selected = NO;
    [UIView animateWithDuration:0.5 animations:^{
        self.moveLineView.centerX = sender.centerX;
    }];
}
- (void)bidBtnClick:(UIButton *)sender{
    self.registerBtn.selected = NO;
    self.objectBtn.selected = NO;
    self.bidBtn.selected = YES;
    [UIView animateWithDuration:0.5 animations:^{
        self.moveLineView.centerX = sender.centerX;
    }];
}
@end
